<template>
  <view class="container">
    <!-- 顶部组件 -->
    <u-navbar
      id="nav-bar"
      :is-back="true"
      :background="{ background: '#fff' }"
      :border-bottom="false"
      title="选择收货地址"
    ></u-navbar>

    <!-- <mescroll-body ref="mescrollRef" @init="mescrollInit" top="0" @down="downCallback"
      :up="upOption" @up="upCallback"> -->
    <view class="address-list">
      <view
        class="address-item"
        v-for="res in siteList"
        :key="res.id"
        @click="handleChoose(res)"
      >
        <u-icon name="map" :size="40" color="#231815"></u-icon>
        <view class="center">
          <view class="item-top">
            <view v-if="res.isDefault" class="label">默认</view>
            <view class="name">{{ res.name }}</view>
            <view class="phone">{{ res.phone }}</view>
            <!-- <view class="tag">
                <text
                  v-for="(item, index) in res.tag"
                  :key="index"
                  :class="{ red: item.tagText == '默认' }"
                  >{{ item.tagText }}</text
                >
              </view> -->
          </view>
          <view class="item-bottom">
            {{ res.province }} {{ res.city }} {{ res.region }}
            {{ res.address }}
          </view>
        </view>
        <u-icon
          name="edit-pen"
          :size="40"
          color="#CCCCCC"
          @click="handleAddressEdit(res.id)"
        >
        </u-icon>
      </view>
    </view>
    <!-- </mescroll-body> -->

    <view class="bottom">
      <view class="bottom-btn1" @click="handleAddAddr">微信导入</view>
      <view class="bottom-btn" @click="handleAddAddr">添加地址</view>
    </view>
  </view>
</template>
<script>
import service from '@/common/service.js';
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';

export default {
  mixins: [MescrollMixin],
  data() {
    return {
      upOption: {
        page: {
          num: 0,
          size: 10,
        },
        noMoreSize: 5,
        empty: {
          tip: '',
        },
      },
      mescroll: null,
      siteList: [
        {
          id: 1,
          name: '张三',
          phone: '15888888888',
          province: '广东省',
          city: '广州市',
          region: '天河区',
          address: '天河区',
          isDefault: true,
        },
      ],
      tradeNo: null,
    };
  },
  onLoad(e) {
    if (e.tradeNo) {
      this.tradeNo = e.tradeNo;
    }
  },
  methods: {
    mescrollInit(mescroll) {
      this.mescroll = mescroll;
    },
    downCallback() {
      this.siteList = [];
      this.mescroll.resetUpScroll();
    },
    upCallback(page) {
      this.getData(page);
    },
    getData(page) {
      const that = this;
      const params = {
        pageNumber: page.num,
        pageSize: page.size,
      };
      service.getAddressList(
        params,
        function (res) {
          if (res && res.data) {
            that.mescroll.endSuccess(res.data.data.length);
            if (page.num == 1) that.siteList = [];
            that.siteList = that.siteList.concat(res.data.data);
          }
        },
        function (res) {}
      );
    },
    handleAddressEdit(id) {
      uni.navigateTo({
        url: '../address/addAddress?type=edit&id=' + id,
      });
    },
    handleChoose(data) {
      uni.$emit('addressData', { addressInfo: data });
      if (this.tradeNo) {
        uni.$emit('tradeNo', { tradeNo: this.tradeNo });
      }
      uni.navigateBack({
        delta: 1,
      });
    },
    handleAddAddr() {
      uni.navigateTo({
        url: '../address/addAddress?type=add',
      });
    },
  },
};
</script>

<style lang="scss">
page {
  background-color: #f7f7f7;
}

.container {
  width: 100%;
  min-height: 100vh;
  padding: 30rpx;
  text-align: center;
  background-color: #f7f7f7;
}

.address-list {
  width: 100%;
  background-color: #ffffff;
  border-radius: 10rpx;

  .address-item {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding: 40rpx 20rpx;
    .center {
      flex: 1;
      padding: 0 20rpx;
      .item-top {
        display: flex;
        font-weight: bold;
        font-size: 34rpx;
        .label {
          margin-right: 20rpx;
          width: 60rpx;
          height: 34rpx;
          line-height: 34rpx;
          color: #cc921f;
          font-size: 20rpx;
          border-radius: 6rpx;
          text-align: center;
          background-color: #fff7e5;
        }
        .name {
          font-size: 26rpx;
          color: #2f2f2f;
        }
        .phone {
          margin-left: 20rpx;
          font-size: 26rpx;
          color: #2f2f2f;
        }
        .tag {
          display: flex;
          font-weight: normal;
          align-items: center;
          text {
            display: block;
            width: 60rpx;
            height: 34rpx;
            line-height: 34rpx;
            color: #ffffff;
            font-size: 20rpx;
            border-radius: 6rpx;
            text-align: center;
            margin-left: 30rpx;
            background-color: rgb(49, 145, 253);
          }
          .red {
            background-color: #ff4019;
          }
        }
      }
      .item-bottom {
        display: flex;
        margin-top: 20rpx;
        font-size: 24rpx;
        justify-content: space-between;
        color: #999999;
      }
    }
  }
}

.bottom {
  position: fixed;
  left: 0;
  bottom: 60rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 30rpx;
  .bottom-btn {
    width: 48%;
    height: 88rpx;
    line-height: 88rpx;
    font-size: 28rpx;
    font-weight: bold;
    color: #ffffff;
    background: linear-gradient(90deg, #332108, #201403);
    border-radius: 16rpx;
  }
  .bottom-btn1 {
    width: 48%;
    height: 88rpx;
    line-height: 88rpx;
    font-size: 28rpx;
    font-weight: bold;
    color: #ffffff;
    background: linear-gradient(90deg, #d9b189, #c5a27f);
    border-radius: 16rpx;
  }
}
</style>
